package com.leedsoft.controller.vo;

import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * Created by leeds on 2017/6/20.
 */
public class StepVo {
    private Long planId;
    private Long stepId;
    private Integer type;//环节类型
    private Integer[] lastCodes;
    private String tasksJson;//反序列化为List<TaskJsonVo>
    private List<TaskJsonVo> taskJsonVoList;

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getTasksJson() {
        return tasksJson;
    }

    public void setTasksJson(String tasksJson) {
        this.tasksJson = tasksJson;
    }

    public Long getPlanId() {
        return planId;
    }

    public void setPlanId(Long planId) {
        this.planId = planId;
    }

    public List<TaskJsonVo> getTaskJsonList() {
        if (taskJsonVoList == null) {
            if (StringUtils.isBlank(tasksJson)) {
                taskJsonVoList = Lists.newArrayList();
            } else {
                taskJsonVoList = new Gson().fromJson(tasksJson, new TypeToken<List<TaskJsonVo>>(){}.getType());
                for (TaskJsonVo task : taskJsonVoList) {
                    task.setHas_to((short) 0);
                    task.setPlan_id(planId);
                    task.setStep_id(stepId);
                }
            }
        }
        return taskJsonVoList;
    }

    public Integer[] getLastCodes() {
        return lastCodes;
    }

    public void setLastCodes(Integer[] lastCodes) {
        this.lastCodes = lastCodes;
    }

    public Long getStepId() {
        return stepId;
    }

    public void setStepId(Long stepId) {
        this.stepId = stepId;
    }
}
